package com.kgc.rb.common.configration;

import com.kgc.rb.common.interceptor.ExceptionInterceptor;
import com.kgc.rb.common.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * 拦截器的配置类
 */
@Configuration
public class InterceptorConfigration extends WebMvcConfigurationSupport {


    @Bean
    public LoginInterceptor getLoginInterceptor() {
        LoginInterceptor loginInterceptor = new LoginInterceptor();
        return loginInterceptor;
    }

    @Bean
    public ExceptionInterceptor getExceptionInterceptor() {
        ExceptionInterceptor exceptionInterceptor = new ExceptionInterceptor();
        return exceptionInterceptor;
    }

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        //在此项目中需要拦截登录操作的请求前面都有一个v
        registry.addInterceptor(getLoginInterceptor())
                .addPathPatterns("/api/v/**");      //设置拦截的路径
        //.excludePathPatterns("/api/doLogin"); //设置不拦截的路径
        registry.addInterceptor(getExceptionInterceptor())
                .addPathPatterns("/api/**");
    }
    /*注意配置拦截器的顺序，先配置谁就先执行谁*/
}
